authenticate.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
const {User} = require('./../models/user');
2
3
let authenticate = (req, res, next) => {
4
    let token = req.header('x-auth');
5
    
6
    User.findByToken(token).then((user) => {
7
        if(!user) {
8
            return Promise.reject();
9
        }
10
        // modify the req object to be used in the route
11
        req.user = user;
12
        req.token = token;
13
        next();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
14
    }).catch((err) => {
15
        res.status(401).send({
16
            err,
17
            status : 401
18
        });
19
    });    
20
}
21
22
module.exports = {authenticate};